/**
 * 用以加密某些字段
 * 因为安装bcrypt包出错，因此用bcryptjs包替代(已解决)
 */
const bcrypt = require("bcrypt");
// const bcrypt = require("bcryptjs");

//加密密码
exports.setPassword = (password) => {
    return new Promise((resolve, reject) => {
        bcrypt.hash(password, 10, (err, hash) => {
            if (err) {
                reject(err);
            } else {
                resolve(hash);
            };
        });
    });
};
//解密密码
exports.getPassword = (password, setPassword) => {
    return new Promise((resolve, reject) => {
        bcrypt.compare(password, setPassword, (err, result) => {
            if (err) {
                reject(err);
            } else {
                resolve(result);
            };
        });
    });
};